package cn.edu.scau.cmi.chenxiaoqin.hibernate.dao;
import org.hibernate.Session;
import org.hibernate.Transaction;

import  cn.edu.scau.cmi.chenxiaoqin.hibernate.domain.*;
import  cn.edu.scau.cmi.chenxiaoqin.hibernate.factory.*;

public class StudentDao {
    public static final String name="name";
    private Session session=new HibernateSessionFactory().getSession(); //打开session
    
    public void save(Student ins)  //增添
    {
    	try {
    		Transaction transation=session.beginTransaction();
    		session.save(ins);
    		transation.commit();
    	}
    	catch(Exception e)
    	{ 
    		throw e;
    	}
    }
    
    public void delete(Student ins)  //删除
    {
    	try {
    		Transaction transation=session.beginTransaction();
    		session.delete(ins);
    		transation.commit();
    	}
    	catch(Exception e)
    	{
    		throw e;
    	}
    }
    
   public void update(Student ins)   //更新
   {
	   try {
		   Transaction transation=session.beginTransaction();
		   session.update(ins);
		   transation.commit();
	   }
	   catch(Exception e)
	   {
		   throw e;
	   }
   }
   
   public void select(Student ins)  //选择导师
   {
	   try {
		   Transaction transation=session.beginTransaction();
		   session.saveOrUpdate(ins);
		   transation.commit();
	   }
	   catch(Exception e)
	   {
		   throw e;
	   }
   }
   
   public Student getById(String id) {
	   try {
		   Student inStu=(Student)session.get("cn.edu.scau.cmi.chenxiaoqin.hibernate.domain.Student", id);
		   return inStu;
	   }
	   catch(Exception e)
	   {
		   throw e;
	   }
   }
}
